<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //写一个假接口，暂时过度一下
    function ajax(url) {
      return new Promise((resolve, reject) => {
        setInterval(() => {
          //成功调用这个
          // resolve({ code: 200, info: 'xxxxxx' })
          //失败调用这个
          reject({ code: 404, info: 'xxxxxx' })
        }, 2000)
      })
    }
    ajax('传入接口地址').then(res => {
      console.log('请求成功', res)
    }).catch(res => {
      console.log('请求失败', res)
    })
    console.log(ajax())
  </script>
</body>

</html>